/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Metodos;

import Atributos.ProfessorSerieTurma;
import Atributos.Serie;
import BD.CriaConexao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Andre
 */
public class ProfessorSerieTurmaMet {
 
    public int id_prof;
    public int id_serie_turma;
    
    private Connection conexao;
        public ProfessorSerieTurmaMet(){
        try{
            this.conexao=(Connection) CriaConexao.getConexao();
        } catch (SQLException ex) {
            Logger.getLogger(ProfessorSerieTurmaMet.class.getName()).log(Level.SEVERE, null, ex);
        }
        }

    public void AdicionaProfSerie(int id_prof, Serie s) {
         try{  
            String sql="insert into professor_serie_turma(id_prof_pst,id_serie_turma_pst)"+"values(?,?)";
            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql)) {
                consulta.setInt(1, id_prof);
                consulta.setInt(2, s.getId());
                consulta.execute();
            }
          }catch (SQLException ex) {
            Logger.getLogger(ProfessorSerieTurmaMet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public List<Serie> BuscarSerieProfessor(int id) throws SQLException {
         String sql = "select serie.id_serie,serie.nome_serie,descricao.descricao_desc ,serie.id_curso_s from serie,professor_serie_turma,descricao where serie.id_serie=professor_serie_turma.id_serie_turma_pst and descricao.id_desc=serie.id_turma_s and professor_serie_turma.id_prof_pst = ?";
        List<Serie> minhaLista;
        try (PreparedStatement stmt = (PreparedStatement) conexao.prepareStatement(sql)) {
            stmt.setInt(1, id);
            try (ResultSet rs = stmt.executeQuery()) {
                minhaLista = new ArrayList<>();
                while (rs.next()) {
                    Serie a1 = new Serie();
                    a1.setId(rs.getInt("id_serie"));
                    a1.setNome(rs.getString("nome_serie"));
                    a1.setTurma(rs.getString("descricao_desc"));
                    a1.setId_curso(rs.getInt("id_curso_s"));
                    minhaLista.add(a1);

                }
            }
        }
        return minhaLista;
    }

    public void Deletar(int a) {
       String sql_f = "delete from professor_serie_turma where id_prof_pst=?";
        try {
            try (java.sql.PreparedStatement consulta_f = conexao.prepareStatement(sql_f)) {
                consulta_f.setInt(1, a);
            
            consulta_f.execute();
            }
        } catch (SQLException ex) {
            Logger.getLogger(ProfessorSerieTurmaMet.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        
        
       
    }
    
       
     public void adiciona(ProfessorSerieTurma pst)throws SQLException{
          try{  
            String sql="insert into professor_serie_turma(id_prof_pst,id_serie_turma_pst)"+"values(?,?)";
            try (PreparedStatement consulta = (PreparedStatement) conexao.prepareStatement(sql)) {
                consulta.setInt(1, pst.id_prof);
                consulta.setInt(2, pst.id_serie_turma);
                consulta.execute();
            }
          }catch (SQLException ex) {
            Logger.getLogger(ProfessorSerieTurmaMet.class.getName()).log(Level.SEVERE, null, ex);
        }
        }   
        
        
        
        
        
        
        
        
}
